﻿using HealthcareSystem.API.Read.Application.Command.Metrics;
using HealthcareSystem.Domain.BasicSettings.Metrics;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Read.Application.CommandHandel.Metrics
{
    /// <summary>
    /// 指标分类请求执行
    /// </summary>
    public class MetricsClassCommandHandler : IRequestHandler<MetricsClassCommand, ApiResult<List<MetricsClass>>>
    {
        private readonly IBaseRepository<MetricsClass> classRep;

        public MetricsClassCommandHandler(IBaseRepository<MetricsClass> classRep)
        {
            this.classRep = classRep;
        }

        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<List<MetricsClass>>> Handle(MetricsClassCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<MetricsClass>> result=new ApiResult<List<MetricsClass>>();
            result.Code=ResultCode.Success;
            result.Message=ResultCode.查询成功.ToString();

            var res=classRep.GetAll().ToList();
            result.Data=res;
            return Task.FromResult(result);



        }
    }
}
